#ifndef _FTADC_H_
#define _FTADC_H_
#include "unione_lite.h"

#define CHANNEL_NUMS            8

#define ADC_DATA0 0x0
#define ADC_DATA1 0x4
#define ADC_DATA2 0x8 
#define ADC_DATA3 0xc
#define ADC_DATA4 0x10
#define ADC_DATA5 0x14
#define ADC_DATA6 0x18
#define ADC_DATA7 0x1c
#define ADC_THRHOLD0 0x80
#define ADC_THRHOLD1 0x84
#define ADC_THRHOLD2 0x88 
#define ADC_THRHOLD3 0x8c
#define ADC_THRHOLD4 0x90
#define ADC_THRHOLD5 0x94
#define ADC_THRHOLD6 0x98
#define ADC_THRHOLD7 0x9c
#define TS_DATA 0xc0
#define TS_THRHOLD 0xc4

#define ADC_CTRL 0x100
#define ADC_MISC 0x104
#define ADC_INTEN 0x108
#define ADC_INTR 0x10c
#define ADC_TPARM 0x110
#define ADC_SMPR 0x114
#define ADC_PRESCAL 0x118
#define ADC_SQR 0x120

#define ADC_DMA0DAT 0x200
#define ADC_DMA0CTRL 0x204
#define ADC_DMA1DAT 0x210
#define ADC_DMA1CTRL 0x214
#define ADC_DMA2DAT 0x220
#define ADC_DMA2CTRL 0x224
#define ADC_DMA3DAT 0x230
#define ADC_DMA3CTRL 0x234


enum ADC_MODE{
     SINGLE_STEP = 0, 
     SINGLE_SCAN,
     CONTINUE_SCAN,
};

typedef void (*adc_callback)(int value, int event);

extern volatile int g_debounce_count[];
extern volatile int g_debounce_gap[];
extern adc_callback g_adc_cb[];

void ftadc_adc_start();
void ftadc_adc_stop();
void ftadc_enable_irq(void);
void ftadc_disable_irq(void);
void ftadc_set_threshold(u8 channel, int thre_event_num, u8 is_high_thre, int thre_value);
u32 ftadc_get_data(u8 ch_num);
int ftadc_init(void);
int ftadc_init_irq(void);
int ftadc_final(void);

#endif
